package edu.fib.upc.erdapfel;

import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.app.Activity;
import android.content.SharedPreferences;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;


public class SettingsActivity extends Activity {

	public static final String FULL_SCREEN = "FullScreen";
	public static final String SAVING_FOLDER = "SavingFolder";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_settings);

		InflateSettings();
	}

	@Override
	public void onBackPressed() {
		super.onBackPressed();
		UpdateSettings();

		Toast.makeText(getApplicationContext(), "Some changes will only take effect after restart.", Toast.LENGTH_LONG).show();				
	}

	public void InflateSettings() {

		SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);

		CheckBox fSBox = (CheckBox) findViewById(R.id.SettingFullScreen);
		fSBox.setChecked(pref.getBoolean(FULL_SCREEN, false));


		EditText eText = (EditText) findViewById(R.id.SettingSaveFolder);
		eText.setText(pref.getString(SAVING_FOLDER, Environment.getExternalStorageDirectory().getPath()+"/download"));					
	}

	public void UpdateSettings() {
		SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);

		CheckBox fSBox = (CheckBox) findViewById(R.id.SettingFullScreen);
		pref.edit().putBoolean(FULL_SCREEN, fSBox.isChecked()).commit();
		
		EditText eText = (EditText) findViewById(R.id.SettingSaveFolder);
		pref.edit().putString(SAVING_FOLDER, eText.getText().toString()).commit();		
	}
}
